#bilibili排名算法 v2.5(2011.4.27)
#针对『热门新番』的特殊规则  - 改
#此规则仅在周点击>200时生效
class Results::R25 < Results::R24
  def is_hot_bangumi?
    if @is_hot_bangumi.nil?
      if work.ac_type_id == 25 && clicks > 200
        bw = BangumiWork.first :include => :bangumi, :conditions => ["work_id = ? and bangumis.status = 1", work_id]
        self[:hot_bangumi] = true if bw
        @is_hot_bangumi = (bw ? true : false)
      else
        @is_hot_bangumi = false
      end
    else
      @is_hot_bangumi
    end
  end

  def comment_fixed
    require 'net/http'
    Net::HTTP.start(BILI_PATH) do |http|
	    feedback_url = "http://#{BILI_PATH}/plus/feedback_tg.php?aid=#{work.wid}"
	    feedback_r = http.get(feedback_url)
	    feedback = feedback_r.body.split('var jshk_num = ').last.to_i
      update_attribute :comments, feedback if feedback > 0 && feedback < comments
    end
  end
end
